<?php
/*
 * POSTGRE CLASS
 * @autor	Albert Moreno Vendrell
 */
class Postgre extends Core {
    private $link;
    private $stmt;
    private $array;

	public function __construct(){
    	
  	}

    /*
     * Make the connection to the database.
     * @autor                           Albert Moreno Vendrell
     */
    private function connect(){
        $this->link 	= pg_connect("host=".$this->server." dbname=".$this->data_base." user=".$this->user." password=".$this->password);

        return $this->link;
    }

    /*
     * Method to execute a SQL statement
     * @autor                           Albert Moreno Vendrell
     */
    public function execute($sql){
        $this->stmt     = pg_Euery($this->link,$sql);

        return $this->stmt;
    }

    /*
     * Method for obtaining a result row of sql statement
     * @autor                           Albert Moreno Vendrell
     */
    public function get_row($stmt,$row){
        if ($row==0){
            $this->array    = pg_fetch_row($stmt);
        }else{
            $this->array    = pg_fetch_row($stmt,$row);
        }
        
        return $this->array;
    }

	/*
	 * Returns the last insert id introduced
	 * @autor                           Albert Moreno Vendrell
	 */
	public function lastID(){
		return pg_last_oid($this->link);
	}
}